package cn.itcast.wushangxiantu.BaseAdapter;

import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;

import cn.itcast.wushangxiantu.R;
import cn.itcast.wushangxiantu.UserData.UserWuQiChongZhu;

public class ZhuangbeiChongZhuGriveViewAdapter extends BaseAdapter {
    private Context context;
    private UserWuQiChongZhu chongZhu;

    public ZhuangbeiChongZhuGriveViewAdapter(Context context) {
        this.context = context;
    }

    public UserWuQiChongZhu getChongZhu() {
        return chongZhu;
    }

    public void setChongZhu(UserWuQiChongZhu chongZhu) {
        this.chongZhu = chongZhu;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (null == chongZhu.getZhuangBei()) {
            return 0;
        } else {
            return chongZhu.getZhuangBei().size();
        }
    }

    @Override
    public Object getItem(int i) {
        return chongZhu.getZhuangBei().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view=View.inflate(context,R.layout.griveview_bag,null);
        ViewHolder viewHolder=new ViewHolder(view);
        viewHolder.tvName.setText(chongZhu.getZhuangBei().get(i).getWpname());
        if (chongZhu.getZhuangBei().get(i).getPz() > 290) {
            viewHolder.tvName.setTextColor(ContextCompat.getColor(context,R.color.wuqi4));
        } else if (chongZhu.getZhuangBei().get(i).getPz() > 260) {
            viewHolder.tvName.setTextColor(ContextCompat.getColor(context,R.color.wuqi3));
        } else if (chongZhu.getZhuangBei().get(i).getPz() > 200) {
            viewHolder.tvName.setTextColor(ContextCompat.getColor(context,R.color.wuqi2));
        } else {
            viewHolder.tvName.setTextColor(ContextCompat.getColor(context,R.color.wuqi1));
        }
        return view;
    }

    class ViewHolder {
        public View rootView;
        public TextView tvName;
        public TextView tvNumber;
        public RelativeLayout li;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tvName = (TextView) rootView.findViewById(R.id.tvName);
            this.tvNumber = (TextView) rootView.findViewById(R.id.tvNumber);
            this.li = (RelativeLayout) rootView.findViewById(R.id.li);
        }

    }
}
